<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">

        <!-- This is a demo program for Temperature & Humidity Long Distence monitor System! (THLDMS) -->
        <title>Example</title>

    </head>
    <body>
        <h1 align = "center">Demo: 基于Raspberry Pi的温湿度远程监控系统</h1>

	<p align="center" style="font-size:20px">
        <!--------------- Login in MariaDB Server ------------------->
        <?php
            $servername = "localhost";
            $username = "root";
	    $password = "raspberry";
	    $dbname = "Temp_Humidity_monitor";

            // Create connection
	    $conn = new mysqli($servername, $username, $password, $dbname);

	    if ($conn->connect_error) {
		die("连接失败: " . $conn->connect_error);
	    }

	    echo "<br><br>最新记录：<br>";
	    $sql = "SELECT s_date, s_time, s_temperature, s_humidity FROM sample WHERE s_order = (SELECT max(s_order) FROM sample)";
            $result = $conn->query($sql);

	    if ($result->num_rows > 0) {
	        while($row = $result->fetch_assoc()) {
		    echo "日期：" . $row["s_date"] . " | 时间：" . $row["s_time"] . " | 温度：" . $row["s_temperature"] . "&#8451 | 湿度：" . $row["s_humidity"] . "%<br>";
		}
	    } else {
		echo "系统中无任何记录！";
	    }

            echo "<br><br><br>当日记录：<br>";
	    $sql = "SELECT s_date, s_time, s_temperature, s_humidity FROM sample WHERE s_date = (SELECT max(s_date) FROM sample) ORDER BY s_order DESC";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "日期：" . $row["s_date"] . " | 时间：" . $row["s_time"] . " | 温度：" . $row["s_temperature"] . "&#8451 | 湿度：" . $row["s_humidity"] . "%<br>";
                }
            } else {
                echo "系统中无任何记录！";
            }

	    $conn->close();
        ?>
	</P>
    </body>
</html>
